Reshape

对输入张量进行重塑操作。在底层实现上,由于张量形状仅由参数定义,该算子执行从输入地址到输出地址的连续数据拷贝。

\[output_i = input_i\]
输入:
  • input - 输入数据起始地址。

  • length - 需拷贝的元素个数。对于复数类型,length 表示复数的个数。

  • core_mask(int, 可选) - 核掩码(仅适用于共享存储版本)。

输出:
  • output - 输出数据起始地址。

支持平台:

FT78NE MT7004

备注

  • FT78NE 支持 int8, int16, int32, fp32, fp64, c64, c128

  • MT7004 支持 fp16, fp32, int16, int32, c64

  • 对于复数类型(c64 / c128),算子会自动处理实部和虚部的连续拷贝,其迁移字节数是普通类型的两倍。

共享存储版本:

void i8_reshape_s(int8_t *input, int8_t *output, int length, int core_mask)
void i16_reshape_s(int16_t *input, int16_t *output, int length, int core_mask)
void i32_reshape_s(int *input, int *output, int length, int core_mask)
void hp_reshape_s(half *input, half *output, int length, int core_mask)
void fp_reshape_s(float *input, float *output, int length, int core_mask)
void dp_reshape_s(double *input, double *output, int length, int core_mask)
void c64_reshape_s(float *input, float *output, int length, int core_mask)
void c128_reshape_s(double *input, double *output, int length, int core_mask)

C调用示例:

 1//FT78NE示例(共享存储,多核并行拷贝)
 2#include <stdio.h>
 3#include "78NE/utils.h"
 4
 5int main(int argc, char* argv[]) {
 6    float *input = (float *)0xA0000000;   // DDR 空间
 7    float *output = (float *)0xB0000000;  // DDR 空间
 8    int length = 960001;
 9    int core_mask = 0x0B;                 // 使用逻辑核 0, 1, 2
10    fp_reshape_s(input, output, length, core_mask);
11    return 0;
12}

私有存储版本:

void i8_reshape_p(int8_t *input, int8_t *output, int length)
void i16_reshape_p(int16_t *input, int16_t *output, int length)
void i32_reshape_p(int32_t *input, int32_t *output, int length)
void hp_reshape_p(half *input, half *output, int length)
void fp_reshape_p(float *input, float *output, int length)
void dp_reshape_p(double *input, double *output, int length)
void c64_reshape_p(float *input, float *output, int length)
void c128_reshape_p(double *input, double *output, int length)

C调用示例:

 1//MT7004 示例(私有存储,单核拷贝)
 2#include <stdio.h>
 3
 4int main(int argc, char* argv[]) {
 5    float *input = (float *)0x10810000;
 6    float *output = (float *)0x10820000;
 7    int length = 1024;
 8    fp_reshape_p(input, output, length);
 9    return 0;
10}